package myJs.myPkg

import myJs.myPkg.jquery.JQuery
import myJs.myPkg.jsext._

import scala.scalajs.js
import scala.language.implicitConversions
import scala.scalajs.js.JSConverters._
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.annotation.JSImport.Namespace

/**
 * Created by yz on 2019/3/14
 */

@js.native
trait BootstrapTableJQuery extends js.Object {

  def bootstrapTable(options: TableOptions): JQuery = scalajs.js.native

  def bootstrapTable(): JQuery = scalajs.js.native

  def bootstrapTable(method: String, parameter: js.Any): JQuery = scalajs.js.native

  def bootstrapTable(method: String, parameter: TableOptions): JQuery = scalajs.js.native

  def bootstrapTable(method: String): JQuery = scalajs.js.native

}

object TableOptions extends TableOptionsBuilder(noOpts)

class TableOptionsBuilder(val dict: OptMap) extends JSOptionBuilder[TableOptions, TableOptionsBuilder](new TableOptionsBuilder(_)) {

  def method(v: String) = jsOpt("method", v)

  def data(v: js.Any) = jsOpt("data", v)

  def columns(v: js.Array[ColumnOptionsBuilder]) = {
    val fmtV = v.map(_.dict.toJSDictionary)
    jsOpt("columns", fmtV)
  }

  def exportOptions(v: ExportOptions) = jsOpt("exportOptions", v)

  def showExport(v: Boolean) = jsOpt("showExport", v)

  def exportDataType(v: String) = jsOpt("exportDataType", v)

  def exportTypes(v: js.Array[String]) = jsOpt("exportTypes", v)

  def exportHiddenColumns(v: Boolean) = jsOpt("exportHiddenColumns", v)

  def showHeader(v: Boolean) = jsOpt("showHeader", v)

  def searchOnEnterKey(v: Boolean) = jsOpt("searchOnEnterKey", v)

  def searchOnButton(v: Boolean) = jsOpt("searchOnButton", v)

  def filterControl(v: Boolean) = jsOpt("filterControl", v)

  def locale(v: String) = jsOpt("locale", v)

  def idField(v: String) = jsOpt("idField", v)

  def parentIdField(v: String) = jsOpt("parentIdField", v)

  def treeShowField(v: String) = jsOpt("treeShowField", v)

  def treeEnable(v: Boolean) = jsOpt("treeEnable", v)

  def rootParentId(v: String) = jsOpt("rootParentId", v)

  def showFooter(v: Boolean) = jsOpt("showFooter", v)

  def height(v: Int) = jsOpt("height", v)

  def filterControlContainer(v: String) = jsOpt("filterControlContainer", v)

  def filterTemplate(v: js.Any) = jsOpt("filterTemplate", v)

  def fixedColumns(v: Boolean) = jsOpt("fixedColumns", v)

  def fixedNumber(v: Int) = jsOpt("fixedNumber", v)

  def fixedRightNumber(v: Int) = jsOpt("fixedRightNumber", v)

  def url(v: String) = jsOpt("url", v)

  def sidePagination(v: String) = jsOpt("sidePagination", v)

  def pageNumber(v: Int) = jsOpt("pageNumber", v)

  def pagination(v: Boolean) = jsOpt("pagination", v)

  def pageList(v: js.Array[js.Any]) = jsOpt("pageList", v)

  def contentType(v: String) = jsOpt("contentType", v)

  def ajax(v: js.Function) = jsOpt("ajax", v)

  def visibleSearch(v: Boolean) = jsOpt("visibleSearch", v)

  def onSort(v: js.Function) = jsOpt("onSort", v)

  def formatLoadingMessage(v: js.Function) = jsOpt("formatLoadingMessage", v)

  def formatShowingRows(v: js.Function) = jsOpt("formatShowingRows", v)

  def formatRecordsPerPage(v: js.Function) = jsOpt("formatRecordsPerPage", v)

  def pageSize(v: Int) = jsOpt("pageSize", v)

  def onLoadSuccess(v: js.Function) = jsOpt("onLoadSuccess", v)

  def onLoadError(v: js.Function) = jsOpt("onLoadError", v)

  def onAll(v: js.Function) = jsOpt("onAll", v)

  def onPageChange(v: js.Function) = jsOpt("onPageChange", v)

  def onRefresh(v: js.Function) = jsOpt("onRefresh", v)

  def onPostBody(v: js.Function) = jsOpt("onPostBody", v)

  def stickyHeader(v: Boolean) = jsOpt("stickyHeader", v)

  def search(v: Boolean) = jsOpt("search", v)

}

trait TableOptions extends js.Object {

}

object ExportOptions extends ExportOptionsBuilder(noOpts)

class ExportOptionsBuilder(val dict: OptMap) extends JSOptionBuilder[ExportOptions, ExportOptionsBuilder](new ExportOptionsBuilder(_)) {

  def csvSeparator(v: String) = jsOpt("csvSeparator", v)

  def csvEnclosure(v: String) = jsOpt("csvEnclosure", v)

  def fileName(v: js.Any) = jsOpt("fileName", v)

  def exportHiddenColumns(v: Boolean) = jsOpt("exportHiddenColumns", v)

  def exportOptions(v: ExportOptions) = jsOpt("exportOptions", v)

}

trait ExportOptions extends js.Object {

}

object ColumnOptions extends ColumnOptionsBuilder(noOpts)

class ColumnOptionsBuilder(val dict: OptMap) extends JSOptionBuilder[ColumnOptions, ColumnOptionsBuilder](new ColumnOptionsBuilder(_)) {

  def field(v: String) = jsOpt("field", v)

  def title(v: String) = jsOpt("title", v)

  def sortable(v: Boolean) = jsOpt("sortable", v)

  def `class`(v: String) = jsOpt("class", v)

  def titleTooltip(v: String) = jsOpt("titleTooltip", v)

  def formatter(v: js.Function) = jsOpt("formatter", v)

  def footerFormatter(v: js.Function) = jsOpt("footerFormatter", v)

  def width(v: Int) = jsOpt("width", v)

  def checkbox(v: Boolean) = jsOpt("checkbox", v)

  def filterControl(v: String) = jsOpt("filterControl", v)

  def searchable(v: Boolean) = jsOpt("searchable", v)

  def filterData(v: String) = jsOpt("filterData", v)

  def filterCustomSearch(v: js.Function) = jsOpt("filterCustomSearch", v)

  def filterControlPlaceholder(v: String) = jsOpt("filterControlPlaceholder", v)

  def filterDatepickerOptions(v: js.Dictionary[js.Any]) = jsOpt("filterDatepickerOptions", v)

  def cellStyle(v: js.Function) = jsOpt("cellStyle", v)

  def operateable(v: Boolean) = jsOpt("operateable", v)

}

trait ColumnOptions extends js.Object {

}

trait BootstrapTableJQueryImplicits {

  implicit def implicitBootstrapTableJQuery(jq: JQuery): BootstrapTableJQuery = {
    jq.asInstanceOf[BootstrapTableJQuery]
  }

}
